﻿@model List<SampleApp.Domain.SysMenu>
@{
    Layout = "~/Default/Views/Shared/_ListLayout.cshtml";
    ViewBag.Title = "菜单";
}


<div class="divToolbar">
    <a href="@Url.Content("~/SysModule/SysMenu/Create")" class="easyui-linkbutton" iconCls="icon-add" plain="true">新建</a>  
    <a id="editButton" href="@Url.Content("~/SysModule/SysMenu/Edit")" class="easyui-linkbutton" iconCls="icon-edit" plain="true">详细</a>  
    <a href="@Url.Content("~/SysModule/SysMenu/List")" class="easyui-linkbutton" iconCls="icon-reload" plain="true">刷新</a>  

</div>

    <div id="updateGridDiv">
    <div id="divListWebGrid">
    @{
        var grid = new WebGrid<SampleApp.Domain.SysMenu>(source: null);
        grid.Bind(source: Model, autoSortAndPage: true,rowCount:@Model.Count);

        
        var index = 0;

        var columns = grid.Columns
            (
            grid.Column(header: "序号", format: (item) => (++index).ToString(), style: "webgrid-col-w25"),
            grid.Column(header: "编号", format: @<text>@item.MenuID</text>, style: "webgrid-col-w100"),
            grid.Column(header: "名称", format: @<text><a href="@Url.Content(string.Format("~/SysModule/SysMenu/Edit/{0}", item.MenuID))">@item.MenuName</a></text>, style: "webgrid-col-w100"),
            grid.Column(header: "图标", format: (item) => item.MenuIcon, style: "webgrid-col-w100"),
            grid.Column(header: "父级", format: @<text>@item.ParentMenuID</text>, style: "webgrid-col-w100"),
            grid.Column(header: "ID", format: @<text>@item.MenuID</text>, style: "webgrid-col-w0 keyCol")

            );

        @grid.GetHtml(
                mode: WebGridPagerModes.All,
                columns: columns,
                selectedRowStyle: "selected",
                tableStyle: "webgrid-table",
                headerStyle: "webgrid-header",
                footerStyle: "paging-number",
                htmlAttributes: new { select1row = true }
                );

    }
		
</div>
    </div>


@section js
{
    <script type="text/javascript">
    
        function retieve(postUrl)
        {
            $.ajax({
                    type: "post",
                    url: postUrl,
                    data:$("form").serialize(),
                    success: function (result) {
                            $("#updateGridDiv").empty().html($("#divListWebGrid",result));
                            bindEvent();
                            }
                    });
        };

        function bindEvent(){
             bindWebGridEvent(
                $(".webgrid-table"),
                function(){
                            postUrl = $(this).attr("href");
                            retieve(postUrl);
                            return false;
                          },
                function(){
                            window.location.href = "@Url.Content("~/SysModule/SysMenu/Edit/")"+getRowKey4Url($(this));
                           }
            );

        };


        $(function () {
            $("#retrieveButton").click(function () {
                var postUrl = "@Url.Content("~/SysModule/SysMenu/List")";
                retieve(postUrl);
                return false;
             });

           $("#editButton").click(function(){
                var r = getSelectedRow($(".webgrid-table"));
                if (r == null)
                    return false;

                window.location.href = $(this).attr("href")+'/'+getRowKey4Url(r);
                return false;
              });

            bindEvent();

         });


    </script>
}
